﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Particle
{
    public class Dot : Canvas
    {
        public double Gravity = 1;
        public double XVelocity = 1;
        public double YVelocity = 1;

        public Dot(byte red, byte green, byte blue, double size)
        {
            double opac = GlobalValue.OPACITY;
            size = GlobalValue.random.Next(GlobalValue.SIZE_MIN, GlobalValue.SIZE_MAX);
            //生成圆圈粒子
            {
                var ellipse = new Ellipse();
                ellipse.Width = size;
                ellipse.Height = size;


                //var myLinearGradientBrush = new LinearGradientBrush();
                //myLinearGradientBrush.StartPoint = new Point(0, 0);
                //myLinearGradientBrush.EndPoint = new Point(0, 0);
                //myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Blue, 0.0));
                //myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Black, 0.3));
                //myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Red, 0.4));
                //myLinearGradientBrush.GradientStops.Add(new GradientStop(Colors.Yellow, 1.0));
                //ellipse.Fill = myLinearGradientBrush;


                ellipse.Fill = new SolidColorBrush(Color.FromArgb(225, red, green, blue));
                ellipse.Opacity = opac;
                ellipse.SetValue(LeftProperty, -ellipse.Width / 2 - 120);
                ellipse.SetValue(TopProperty, -ellipse.Height / 2 - 80);
                Children.Add(ellipse);
            }
        }

        //制作一个绑定属性
        public double X
        {
            get { return (double)(GetValue(LeftProperty)); }
            set { SetValue(LeftProperty, value); }
        }

        public double Y
        {
            get { return (double)(GetValue(TopProperty)); }
            set { SetValue(TopProperty, value); }
        }

        public void RunFirework()
        {
            X = X + XVelocity;
            Y = Y + YVelocity;
            Opacity += GlobalValue.OpacityInc;
            YVelocity += Gravity;
        }
    }
}
